package eu.boss.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.codehaus.jackson.annotate.JsonIgnore;


/**
 * Message sent by server after login request
 * @author Arnaud
 *
 */
public class StatsMessage implements Serializable{
	

	private static final long serialVersionUID = 3722924909900264084L;
	private List<Team> teams;
	private List<Player> players;
	
	public StatsMessage(){}
	
	public StatsMessage(List<Team> tList, List<Player> pList)
	{
		teams = new ArrayList<Team>();
		for (int i=0; i<tList.size(); i++)
		{
			teams.add(tList.get(i));
		}
		
		players= new ArrayList<Player>();
		for (int i=0; i<tList.size(); i++)
		{
			teams.add(tList.get(i));
		}
	}

	
	@JsonIgnore
	public StatsMessage(String s){
		teams = new ArrayList<Team>();
		Team shadow = new Team(TeamType.SHADOW, 0, 0);
		Team neutral = new Team(TeamType.NEUTRAL, 0, 0);
		Team hunter = new Team(TeamType.HUNTER, 0, 0);
		teams.add(shadow);
		teams.add(hunter);
		teams.add(neutral);
		players = new ArrayList<Player>();
	}
	
	
	public List<Team> getTeams() {
		return teams;
	}

	public void setTeams(List<Team> teams) {
		this.teams = teams;
	}
	
	public List<Player> getPlayers() {
		return players;
	}

	public void setPlayers(List<Player> players) {
		this.players = players;
	}
	

	/**
	 * Sort playerlist by ratio
	 */
	@JsonIgnore
	public void sortTeamList()
	{
		Collections.sort(teams);
	}
	
	
	@JsonIgnore
	public Team getTeam(TeamType t){
		for (int i=0; i<3; i++){
			if (t==teams.get(i).getTeam())
				return teams.get(i);
		}
		return null;
	}
	
	
	/**
	 * Sort playerlist by ratio
	 */
	@JsonIgnore
	public void sortPlayerList()
	{
		Collections.sort(players);
	}
	
	
	/**
	 * reinitialize every single player of the list
	 */
	@JsonIgnore
	public void reinitPlayerList(){
		for (int i=0; i<players.size(); i++)
		{
			players.get(i).reInit();
		}
	}
	
	/**
	 * reinitialize every single Team of the list
	 */
	@JsonIgnore
	public void reinitTeamList(){
		for (int i=0; i<teams.size(); i++)
		{
			teams.get(i).reInit();
		}
	}
	
	
	/**
	 * delete every single player of the list
	 */
	@JsonIgnore
	public void deletePlayers(){
		players.clear();
	}	
}
